//上传图片的方法
/**
 * 
 * @param {云存储文件夹目录} nameFile ||folder
 * @param {上传过来的文件目录} path 
 */
//上传一张图
async function oneUpFile(nameFile, path) {
  var id = null
  //获取文件的真实地址
  await wx.cloud.uploadFile({
    cloudPath: nameFile,
    filePath: path, // 文件路径
  }).then(res => id = res.fileID)
  return await wx.cloud.getTempFileURL({
    fileList: [{
      fileID: id
    }]
  })
}

//上传多张图
function upFile(folder, path) {
  wx.showLoading({
    title: '上传图片中',
    mask: true
  })
  var data = Date.now()
  var url = []
  path.forEach((item, idx) => {
    let urlName = folder + data + idx
    url.push(oneUpFile(urlName, item))
  })
  //将上传的图片地址放入promise返回
  return Promise.all(url)
}
module.exports.oneUpFile = oneUpFile
module.exports.upFile = upFile
